<?php

/***************************************************************\
* FILE:		sys/pages/register.inc
* SECTION:	pages > user management
* FUNCTION:	
* USES:	
* INCLUDES:		
* PRODUCES:	
* LAUNCHES:	
\***************************************************************/

/**
 * adds extra access checks, dependent on page state
 */
function page_inc_check_access() {
	check_access("VIEW");
	if ($_SESSION['user_id'])
		endpage("already registered");
}


function page_inc_execute_action($action) {
	switch($action) {
		default:
			add_alert("unknown action: $action");
			break;
	}
}


/**
 * execute page logic
 */
function page_inc_execute() {
	global $PAGE, $CONFIG;

	if (!$_GET['code'] or !$PAGE['id'])
		errorpage(9);

	$sqlresult = db_do_query(db_query_select(array(array('*')), array("MEMBER"), ereg("^[0-9]+$", $PAGE['id']) ? "user_id = {$PAGE['id']}" : "nick = '{$PAGE['id']}'"));
	
	if (db_num_rows($sqlresult) != 1)
		errorpage(9);
		
	$user = db_fetch_array($sqlresult);
	
	if ($_GET['code'] == ("ACTIV" . md5("{$user['nick']}{$user['email']}blablabla6"))) {
	
		db_do_query(db_query_update(array('member_since', 'title'), array('member_since', '"boomdraak"'), "MEMBER", "user_id = {$user['user_id']}"));
		
		login($user['user_id']);

		endpage("OK, je registratie is nu compleet. Veel plezier op de site, en vul bijtijds ook je <a href=/service/.profile?action=edit>profiel</a> verder in (je wordt er automatisch naar dooverwezen zodadelijk). <script language=JavaScript>setTimeout(\"location.href='/service/.profile?action=edit'\", 5000);</script>");
	
	} else
		errorpage(12);
}

/**
 * dress up page content using skin stuff
 */
function page_inc_dress() {}

?>